package hotel.meituan.oversea.biz.controller;

import com.alibaba.fastjson.JSON;
import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.utils.Result;
import hotel.meituan.oversea.biz.service.MtHotelGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 美团酒店产品价格Controller
 * @author qiuyy
 * @date 2020-05-15
 */
@Slf4j
@RestController
@RequestMapping("/mtHotelGoodsRule")
@Api(value = "MtHotelGoodsRuleController", tags = {"美团酒店产品规则接口"})
public class MtHotelGoodsRuleController {
    @Autowired
    private MtHotelGoodsService mtHotelGoodsService;
    @PostMapping("/checkGoodsCancel")
    @ApiOperation(value = "校验美团产品是否可取消",notes="必须经过auth授权")
    public Result<Object> aspcheckGoodsCancel(@RequestBody Map map){
        log.info("校验美团产品是否可取消={}", JSON.toJSONString(map));
        String mtHotelId = String.valueOf(map.get("mtHotelId"));
        String checkinDate = String.valueOf(map.get("checkinDate"));
        String mtGoodsId = String.valueOf(map.get("mtGoodsId"));
        if(null == mtHotelId){
            return new Result<>("mtHotelId不可为空",CommonConstants.REQUEST_ERROR);
        }
        if(null == mtGoodsId){
            return new Result<>("mtGoodsId不可为空",CommonConstants.REQUEST_ERROR);
        }
        if(null == checkinDate){
            return new Result<>("checkinDate不可为空",CommonConstants.REQUEST_ERROR);
        }
        Result result = mtHotelGoodsService.checkGoodsCancel(mtHotelId,mtGoodsId,checkinDate);
        log.info("校验美团产品是否可取消 aspcheckGoodsCancel 返回：{}", JSON.toJSONString(result));
        return result;
    }

    @PostMapping("/getCancelByGoodsInfo")
    @ApiOperation(value = "查询产品每日取消规则",notes="必须经过auth授权")
    public Result<Object> getCancelByGoodsInfo(@RequestBody Map map){
        log.info("查询产品每日取消规则={}", JSON.toJSONString(map));
        String mtHotelId = String.valueOf(map.get("mtHotelId"));
        String mtGoodsId = String.valueOf(map.get("mtGoodsId"));
        String checkinDate = String.valueOf(map.get("checkinDate"));
        String checkoutDate = String.valueOf(map.get("checkoutDate"));
        if(null == mtHotelId){
            return new Result<>("mtHotelId不可为空",CommonConstants.REQUEST_ERROR);
        }
        if(null == mtGoodsId){
            return new Result<>("mtGoodsId不可为空",CommonConstants.REQUEST_ERROR);
        }
        if(null == checkinDate){
            return new Result<>("checkinDate不可为空",CommonConstants.REQUEST_ERROR);
        }
        if(null == checkoutDate){
            return new Result<>("checkoutDate不可为空",CommonConstants.REQUEST_ERROR);
        }
        Result result = mtHotelGoodsService.getCancelByGoodsInfo(mtHotelId,mtGoodsId,checkinDate,checkoutDate);
        log.info("校验美团产品是否可取消 aspcheckGoodsCancel 返回：{}", JSON.toJSONString(result));
        return result;
    }

}
